What is camelcase?
The camelcase npm package is used to convert strings to camel case. This means it takes input strings with spaces, hyphens, underscores, or a mix of different delimiters and converts them into a string where the first letter of each word is capitalized except for the first word, and all the words are joined without spaces.
What are camelcase's main functionalities?
String Conversion to Camel Case
Converts a hyphenated string to camel case.
"foo-bar".pipe(camelCase); // 'fooBar'
Handling Multiple Delimiters
Converts a string with multiple delimiters to camel case.
"foo_bar--baz foo".pipe(camelCase); // 'fooBarBazFoo'
Preserving Consecutive Uppercase Characters
Converts a string to camel case while preserving consecutive uppercase characters.
"foo-BAR".pipe(camelCase({ pascalCase: false })); // 'fooBAR'
Converting to Pascal Case
Converts a string to pascal case, which is similar to camel case but with the first letter capitalized.
"foo-bar".pipe(camelCase({ pascalCase: true })); // 'FooBar'
Other packages similar to camelcase
change-case
A package that provides various case conversion utilities including camel case, snake case, pascal case, and more. It offers more comprehensive case conversion options compared to camelcase.
to-camel-case
A package that converts a string to camel case. It is similar to camelcase but is a smaller package with fewer features and customization options.
param-case
This package is designed to convert strings to param case (kebab case). While it serves a different purpose, it is related in the sense that it deals with string case conversion, just like camelcase.
camelcase
Convert a dash/dot/underscore/space separated string to camelCase: foo-bar
→ fooBar
Install
$ npm install --save camelcase
Usage
const camelCase = require('camelcase');
camelCase('foo-bar');
camelCase('foo_bar');
camelCase('Foo-Bar');
camelCase('--foo.bar');
camelCase('__foo__bar__');
camelCase('foo bar');
console.log(process.argv[3]);
camelCase(process.argv[3]);
camelCase('foo', 'bar');
camelCase('__foo__', '--bar');
Related
License
MIT © Sindre Sorhus